

// Refs: https://codeboard.io/projects/11587?view=2.1-21.0-22.0

import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException
import java.io.OutputStream
import java.util.Random

class Hello {

  fun doesNotCauseNPE() {
    val a: Pointers.A? = Pointers.mayReturnNull(10)
    a!!.method()
  }

  fun mayCauseNPE() {
    val rng = Random();
    val a: Pointers.A? = Pointers.mayReturnNull(rng.nextInt())
    // FIXME: should check for null before calling method()
    a!!.method()
  }

  // @Throws(IOException::class)
  // fun mayLeakResource() {
  //   val stream: OutputStream? = Resources.allocateResource()
  //   if (stream == null) {
  //     return
  //   }

  //   try {
  //     stream.write(12)
  //   } finally {
  //     // FIXME: should close the stream
  //   }
  // }

  /**
   * This method should be rewritten with nested try { ... } finally {
   * ... } statements, or the possible exception raised by fis.close()
   * should be swallowed.
   */
  // @Throws(IOException::class)
  // fun twoResources() {
  //   var fis: FileInputStream? = null;
  //   var fos: FileOutputStream? = null;
  //   try {
  //     fis = FileInputStream(File("whatever.txt"));
  //     fos = FileOutputStream(File("everwhat.txt"));
  //     fos.write(fis.read());
  //   } finally {
  //     if (fis != null) { fis.close(); }
  //     if (fos != null) { fos.close(); }
  //   }
  // }

  companion object {
    @JvmStatic
    fun main(args: Array<String>) {
      println("Hello Infer world");
    }
  }
}
